package com.wlyuan.open.domain.source.assembler;

import com.wlyuan.core.domain.MappingIds;
import com.wlyuan.core.marker.NamedStatus;
import com.wlyuan.open.dto.OpenTransportSyncDTO;
import com.wlyuan.open.dto.transport.OpenTransportRelationSyncDTO;
import com.wlyuan.open.dto.transport.TransportGoodsDTO;
import com.wlyuan.transport.rewrite.dto.WaybillUpDownRewriteDTO;
import com.wlyuan.transport.rewrite.dto.open.WaybillOpenGoodsDTO;
import com.wlyuan.transport.rewrite.dto.open.WaybillOpenRewriteDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

/**
 * @author lijing
 * @description
 */
public class TransportAssembler {

    private static final Assembler ASSEMBLER = Mappers.getMapper(Assembler.class);

    @Mapper(uses = {
            MappingIds.class,
    }, imports = {
            NamedStatus.class,
    })
    public interface Assembler {

        @Mappings({
                @Mapping(source = "arguments", target = "arguments"),
                @Mapping(source = "vehicle", target = "arguments.vehicle"),
        })
        WaybillOpenRewriteDTO assemble(OpenTransportSyncDTO source);

        @Mappings({
                @Mapping(source = "goodsTypeName", target = "type"),
                @Mapping(source = "desc", target = "remarks"),
                @Mapping(source = "materialCode", target = "barcode"),
        })
        WaybillOpenGoodsDTO assemble(TransportGoodsDTO source);

        @Mappings({
                @Mapping(source = "upTransportId", target = "upWaybillId"),
                @Mapping(source = "downTransportId", target = "downWaybillId"),
        })
        WaybillUpDownRewriteDTO assemble(OpenTransportRelationSyncDTO source);
    }

    public static WaybillOpenRewriteDTO assemble(OpenTransportSyncDTO source) {
        return ASSEMBLER.assemble(source);
    }

    public static WaybillUpDownRewriteDTO assemble(OpenTransportRelationSyncDTO source) {
        return ASSEMBLER.assemble(source);
    }
}
